<#cenluan title="编辑活动" menu="activity" markdown="true" validate="true" datepicker="true">
	<ol class="breadcrumb mb20">
		<li><a href="/activity">活动</a></li>
		<li><a href="/activity/show/${activity.id}">活动详情</a></li>
		<li class="active">编辑</li>
	</ol>
	<form class="form-horizontal" method="post" id="activityForm">
		<input type="hidden" name="activity.id" value="${activity.id}">
		<div class="form-group">
			<label class="control-label col-md-2">标题</label>
			<div class="col-md-10">
				<input class="form-control" type="text" name="activity.title"
				 required minlength="3" maxlength="32" placeholder="标题在3-32字之间" value="${activity.title}">
			</div>
		</div>
		<!-- TODO 时间逻辑判断 -->
		<%if(activity.start>date()){%>
		<div class="form-group">
			<label class="control-label col-md-2">时间</label>
			<div class="col-md-5">
				<input class="form-control date-field" type="text" name="activity.start" 
				required value="${activity.start,'yyyy-MM-dd HH:mm:ss'}">
			</div>
			<div class="col-md-5">
				<input class="form-control date-field" type="text" name="activity.end" 
				required value="${activity.end,'yyyy-MM-dd HH:mm:ss'}">
			</div>
		</div>	
		<%}else{%>
		<div class="form-group">
			<label class="control-label col-md-2">时间</label>
			<div class="col-md-10">
				<p class="form-control-static">${activity.start,'yyyy-MM-dd HH:mm'}至${activity.end,'yyyy-MM-dd HH:mm'}</p>
			</div>
		</div>	
		<%}%>
		<div class="form-group">
			<label class="control-label col-md-2">内容</label>
			<div class="col-md-10">
				<textarea name="activity.content" id="content">${activity.content}</textarea>
			</div>
		</div>	
		<div class="form-group">
			<div class="col-md-3 col-md-offset-2">
				<button class="btn btn-primary btn-block" type="submit">提交</button>
			</div>
			<div class="col-md-7">
				<p class="form-control-static text-danger" id="msg"></p>
			</div>
		</div>	
	</form>
	<script>
		$(function(){
			//markdown
			$("#content").markdown({
				language : "zh",
				resize : "vertical",
				fullscreen : false,
				width : "100%",
				height : "300"
			});
			$(".date-field").datetimepicker({
				format:"yyyy-mm-dd hh:ii:ss",
				todayBtn:true,
				todayHighlight:true,
				language:"zh-CN"
			});
			$("#activityForm").validate({
				submitHandler:function(form){
					$(form).find(":submit").button("loading");
					$(form).ajaxSubmit({
						url:"/activity/update",
						success:function(json){
							var msg = "保存成功";
							if(!json.ok){
								msg = json.msg;
							}
							var timeId = $("#msg").data("time-id");
							if(timeId){
								clearTimeout(timeId);
							}
							$("#msg").text(msg)
							timeId = setTimeout(function(){
								$("#msg").empty();
							}, 2000);
							$("#msg").data("time-id",timeId);
							$(form).find(":submit").button("reset");
						}
					});				
				}
			});
		});
	</script>
</#cenluan>